Title: SQL W3S (By-BKK) / 117 Views
Tags: Obsidian_to_Anki

Q: What is an SQL view?
A: A view is a virtual table based on the result-set of an SQL statement

Q: True or False: An SQL view stores physical data in the database
A: False

Q: Does a view show up-to-date data when queried?
A: Yes, views always show current data since the database recreates the view each time it is queried

Q: What SQL statement is used to create a view?
A: CREATE VIEW

Q: Show the basic syntax to create an SQL view
A: CREATE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;

Q: Fill in the blank: A view contains rows and columns from _ in the database
A: One or more real tables

Q: What is an example of a CREATE VIEW statement for Brazilian customers?
A: CREATE VIEW [Brazil Customers] AS SELECT CustomerName, ContactName FROM Customers WHERE Country = 'Brazil';

Q: How would you query data from a view named [Brazil Customers]?
A: SELECT * FROM [Brazil Customers];

Q: Example: How do you create a view to show products above the average price?
A: CREATE VIEW [Products Above Average Price] AS SELECT ProductName, Price FROM Products WHERE Price > (SELECT AVG(Price) FROM Products);

Q: How do you update an existing SQL view?
A: Use CREATE OR REPLACE VIEW statement

Q: Show the syntax to update an SQL view
A: CREATE OR REPLACE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;

Q: What is an example of updating [Brazil Customers] view to add the City column?
A: CREATE OR REPLACE VIEW [Brazil Customers] AS SELECT CustomerName, ContactName, City FROM Customers WHERE Country = 'Brazil';

Q: What statement removes or deletes an SQL view?
A: DROP VIEW view_name;

Q: What is an example of dropping the [Brazil Customers] view?
A: DROP VIEW [Brazil Customers];

Q: Reverse card: CREATE VIEW is used to create a _ in SQL
A: What is used to create a view in SQL?

Q: Reverse card: DROP VIEW view_name deletes a view from the database
A: What SQL statement deletes a view from the database?

Q: True or False: Views can be created from the result of joining multiple tables
A: True